<template>
  <div class="page-department">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>操作日志
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-searchHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe63d;</span> 筛选查询
          </p>
          <div class="right">
            <button @click="findRes">查询结果</button>
          </div>
        </div>
      </div>
    </div>
    <div class="component-search-box">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="操作人员：">
          <el-input clearable v-model="formInline.search" placeholder="姓名"></el-input>
        </el-form-item>
        <el-form-item label="操作日期" style="width:500px;">
          <el-date-picker
            v-model="formInline.value1"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="timestamp"
            :default-time="['00:00:00', '23:59:59']">
          </el-date-picker>
        </el-form-item>
      </el-form>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            {{title}}
          </p>

        </div>
      </div>
    </div>

    <div class="table">
      <el-table
        ref="multipleTable"
        :data="info"
        tooltip-effect="dark"
        style="width:100%"
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" align="center" width="55"></el-table-column>
        <el-table-column label="编号" align="center" width="80" type="index"></el-table-column>
        <el-table-column label="操作者" align="center" prop="username"></el-table-column>
        <el-table-column label="操作日期" align="center" >
          <template slot-scope="scope">
            {{scope.row.operDate | dateFilter}}
          </template>
        </el-table-column>
        <el-table-column label="操作类型" align="center" prop="operType"></el-table-column>
        <el-table-column label="操作记录" align="center" prop="operDesc"></el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div class="component-paging" v-if="info.length > 0">
      <div class="table-bottom">
        <div class="bottom-left" style="margin-left: 42px;">
          <button @click="handleDelete">删除</button>
        </div>
        <div class="paging">
          <div class="paging-left">
            <p>
              共
              <span>{{Math.ceil(total/pageSize)}}</span> 页/
              <span>{{total}}</span> 条数据
            </p>
          </div>
          <el-pagination
            background
            @size-change="SizeChange($event,dataInit,currentPage,pageSize)"
            @current-change="CurrentChange($event,dataInit,currentPage,pageSize)"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "operation",
  data() {
    return {
      title: "数据列表",
      outputList: true,
      info: [],
      formInline:{
        search: "",
        value1: "",
      },
      // 数据总条数
      total: 1,
      // 每页显示数据的条数
      pageSize: 10,
      // 当前显示的页面页码
      currentPage: 1,
      multipleSelection:[],//全选
    };
  },
  mounted(){
    this.dataInit();
  },
  methods: {
      //查询数据列表
    dataInit(){
      var dateArr = ["",""];
      if(this.formInline.value1!=undefined){
        dateArr = this.formInline.value1;
      }
      let that = this;
      let suCb = function(res){
          console.log(res.data)
        that.info = res.data.map.records;
        that.total = res.data.map.rowCount;
      }
      let erCb = function(res){
        console.log(res)
      }
      let postData = {
        pageCurrent: that.currentPage.toString(),
        pageSize:that.pageSize.toString(),
        user:that.formInline.search,
        startT:dateArr[0]!=undefined?dateArr[0]+"":"",
        endT:dateArr[1]!=undefined?dateArr[1]+"":""
      }
      let palyParam = {
        url: "/api/web/Log/getOperateLog",
        methods:'post',
        data: postData,
        success: suCb,
        error: erCb,
      }
      that.$https(palyParam)
    },
    //全选
    handleSelectionChange(val) {
      let arr = [];
      if(val.length > 0){
        val.forEach( item => {
          arr.push(item.operId)
          this.multipleSelection = arr;
        })
      }else{
        this.multipleSelection = [];
      }
    },
    //删除
    handleDelete() {
      if(this.multipleSelection != undefined && this.multipleSelection.length >= 1){
          this.del();
      }else{
        this.$alert('请选择所要删除的内容', '提示', {
          confirmButtonText: '明白了',
        });
      }
    },
    //删除函数
    del(){
      let that = this;
      let suCb = function(res){
        that.$message({
          message: '删除成功',
          type: 'success'
        });
        that.dataInit(that.currentPage,that.pageSize)
      }
      let erCb = function(res){
        console.log(res)
      }
      let postData = {
        operId: that.multipleSelection
      }
      let palyParam = {
        url: "/api/web/Log/deleteByuser",
        methods:'post',
        data: postData,
        success: suCb,
        error: erCb,
      }
      that.$https(palyParam)
    },
    findRes(){
      this.currentPage = 1;
      this.dataInit();
    }

  },
};
</script>

<style scoped>
.component-searchHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
}

.component-searchHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-searchHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  line-height: 45px;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-searchHeader .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 30px;
}

.component-searchHeader .right button {
  padding: 0 15px;
  height: 30px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 12px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-searchHeader .right button:hover {
  background-color: #f3f3f3;
}

.component-search-box {
  width: 1100px;
  height: 60px;
  box-sizing: border-box;
  background-color: #fff;
  border: 1px solid #e4e4e4;
  border-top: none;
  margin: 0 auto;
  text-align: left;
  padding-left: 30px;
  line-height: 60px;
}

.component-search-box .el-input__inner {
  height: 36px;
  display: inline-block;
}

.component-listHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
  border-bottom: 0;
}

.component-listHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-listHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  line-height: 45px;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-listHeader .search-header .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 10px;
}

.component-listHeader .search-header .right button {
  padding: 0 15px;
  height: 30px;
  width: 80px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 14px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-listHeader .search-header .right button:hover {
  background-color: #f3f3f3;
}

.component-listHeader .search-header .right .right-select-margin {
  margin-top: 6px;
  margin-right: 8px;
}

.table {
  width: 1100px;
  margin: 0 auto;
}
</style>
